Skip to content

fix: report invalid SMB names on cross-storage move/copy instead of a 500 - #67678

Open
1358 wants to merge 2 commits into
nextcloud:masterfrom
1358:fix/smb-invalid-path-cleanup
Open

1358 wants to merge 2 commits into
nextcloud:masterfrom
1358:fix/smb-invalid-path-cleanup

Conversation

@1358

@1358 1358 commented Dec 4, 2026 •

Copy link
Copy Markdown

Summary

Moving a folder to SMB external storage fails with an HTTP 500 when a file inside has a name SMB can't store, e.g. 14:15.mp4. This is the defensive part from #65715, kept separate from the path pre-validation so it can be backported:

  • Common::copyFromStorage() no longer lets a failing cleanup of the partially written target abort the traversal.
  • An InvalidPathException from writing the target is rethrown after the cleanup. DAV MOVE and COPY answer it with 400 Invalid Path, as they already do for an invalid top-level name.
  • SMB: fopen() maps icewind's InvalidPathException to OCP\Files\InvalidPathException, and unlink() returns false for such a path.

Before, the client got the exception of the failed cleanup as a 500. Guarding the cleanup alone would turn that into an empty 403, and the Files app would only show "Some files could not be moved". Now the toast names the file and the character, and there is no "Uncaught exception" in the log anymore.

Not fixed here: the files copied before the failing one stay in the target. #67680 validates the tree against the SMB backend before copying.

I left out mapping InvalidPathException in SMB::getFileInfo(). On its own it lets a direct upload of 14:15.mp4 to SMB get past file_exists() and fail when the part file is renamed, which swallows the exception. The client then gets "Could not rename part file to final file" instead of the file name. With the pre-validation that path isn't reached anymore, so the mapping is part of #67680.

The commits apply cleanly to stable35, stable34 and stable33.

How to test

  1. Add an SMB external storage, e.g. against ghcr.io/servercontainers/samba as in the files-external CI job.
  2. Create a folder with a.txt, 14:15.mp4 and z.txt and move it onto the SMB mount in the Files app.
  3. Before: HTTP 500, the toast shows the raw icewind exception. After: HTTP 400, the toast shows Invalid request for Invalid path "/<folder>/14:15.mp4", ":" is not allowed (InvalidPathException). The source folder stays complete.

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

1358 added 2 commits December 3, 2026 12:01
When writing a file to the target storage fails, copyFromStorage()
deletes the partially written target. If that unlink() throws as well,
the exception escapes the folder traversal and the move or copy ends in
an HTTP 500. A target name the storage cannot store must still reach
the client, so it can tell which file failed, as it already does when
the top-level target name is invalid.

Signed-off-by: Tom Mittelstädt <1583407+1358@users.noreply.github.com>
icewind/smb throws its own InvalidPathException for names containing
characters SMB does not allow, e.g. ":". fopen() let it escape
unmapped, and unlink() threw for a path that cannot exist on the share.

Signed-off-by: Tom Mittelstädt <1583407+1358@users.noreply.github.com>
@1358
1358 marked this pull request as ready for review December 4, 2026 07:33
@1358
1358 requested review from a team as code owners December 4, 2026 07:33
@1358
1358 requested review from Altahrim, GhassenKefi, salmart-dev and vlotysh and removed request for a team December 4, 2026 07:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant